Repository navigation
fix(github-backup): validate plan/state shape at load — poison entries named and skipped (#6637) - #6696
Conversation
…s named and skipped, never fatal (#6637)
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 52 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3c8af48f5d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| for repo, entry in state.items(): | ||
| if not isinstance(entry, dict): | ||
| problems.append( | ||
| f"{source}: entry for {repo!r} is {_shape(entry)}, " | ||
| f"expected an object — dropped" |
There was a problem hiding this comment.
Preserve webhook-drainer timestamps when validating state
When the webhook drainer has successfully fetched a repository, state.json legitimately contains a numeric drain_last::<repo> timestamp, written by drain_queue.py:251–259 and used to enforce its 15-minute coalescing window. This validator treats those timestamps as malformed entries and drops them. Because fetch_mirrors.main() writes the sanitized state back to disk, every daily fetch erases the drainer's coalescing metadata, allowing the next webhook drain to fetch repositories again inside that window. Preserve and validate these bookkeeping entries separately from per-repository objects.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 2e06082 — thank you, this was a real catch. validate_state now validates the drainer's bookkeeping keys under their own shapes and preserves them: drain_last::<repo> must be a number (bool excluded) and drain_fail::<repo> stays on the object path; a wrong-shaped drain_last:: is named and dropped instead of silently kept. Two regression tests added (test_drain_bookkeeping_entries_are_preserved, test_drain_last_with_wrong_shape_is_named_and_dropped); full github-backup suite green, including test_drain_queue.py 82/82.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2e06082eee
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| class ValidatePlanTests(unittest.TestCase): | ||
| def test_valid_plan_passes_through(self): | ||
| plan = [{"repo": "a/b", "size_kb": 1}, {"repo": "c/d"}] | ||
| entries, problems = ghb_common.validate_plan(plan) | ||
| self.assertEqual(entries, plan) | ||
| self.assertEqual(problems, []) |
There was a problem hiding this comment.
Add property tests for the new shape-validation invariants
The new plan/state validation coverage consists entirely of fixed examples, but the root AGENTS.md explicitly requires property tests for parsers and other code with meaningful invariants. These validators fit that requirement: generated JSON inputs can check that accepted plan entries always have string repository names, malformed entries cannot invalidate valid siblings, and valid bookkeeping state survives validation unchanged. Add generated invariant coverage alongside these regression examples to satisfy the repository's testing doctrine.
AGENTS.md reference: AGENTS.md:L41-L45
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Added in the follow-up commit just pushed — ShapePropertyTests in tests/test_plan_state_shape.py: a seeded stdlib generator (2,000 generated plans + 2,000 generated states per run, JSON round-tripped so the validators see only json.load-shaped data) checked against independent oracle restatements of the shape contracts — accepted plan entries are exactly the dict-with-string-repo entries in order with one problem per invalid entry; state validation matches the oracle (including drain_last::/drain_fail:: shapes), is idempotent, and a poison entry appended to a plan never changes the verdict on its siblings (500 generated cases). Suite is stdlib-only per the github-backup test convention (no hypothesis dependency); 20/20 tests pass in <0.1s.
Fixes #6637.
fetch_mirrors.pyloadedplan.json/state.jsonwith barejson.loadand subscripted the results unguarded, so one valid-JSON-but-wrong-shape entry (a plan entry of123, a state entry of"oops", a stringfail_days) crashed the whole daily fetch with a rawTypeError/KeyError/AttributeError— and re-crashed every subsequent run, since the crashing run never rewrote the file. Triage by lane code-a confirmed every shape on current main and routed this issue as the fix vehicle.Change — shared validation lands once, in
ghb_common(per the #6637/#6653 coordination note)ghb_common.validate_plan/validate_state/load_plan/load_state/report_problems: a plan entry that is not an object with a stringrepois reported by index and skipped; a per-repo state entry that is not an object is dropped by name; a non-listfail_daysinside a state entry is reset to[]with a named problem; a wrong-shape top level is a single named problem treated as empty. Problems print to stderr (the timer log is where these failures surface).fetch_mirrors: plan/state load through the new helpers;fetch_reposanitizes a poison per-repo entry /fail_daysvia_repo_stateand proceeds;record_failure_dayraises a namedValueErroron a non-listfail_daysinstead of escaping asTypeError/KeyError; the chronic-failure check only counts listfail_days. Valid behaviour (coalescing, streak/chronic accounting, manifest regeneration) is unchanged.manifest.py build()andclone_all.py main()load the plan through the sameload_plan(manifest alsoload_state), so the sharedplan.jsonvalidation exists exactly once. Note for github-backup(manifest): a valid-JSON but wrong-shape plan/state entry crashes the whole manifest regeneration — MANIFEST.json (the DR source) is never rewritten #6653:manifest.py's plan/state load is now shape-validated by this PR; github-backup(manifest): a valid-JSON but wrong-shape plan/state entry crashes the whole manifest regeneration — MANIFEST.json (the DR source) is never rewritten #6653's remaining scope is its own regression tests for MANIFEST regeneration.Tests
tests/test_plan_state_shape.py(15 tests): the five named shapes (plan entry123, plan entry missingrepo, state entry as string, state top-level list,fail_daysas string) plus controls,main()end-to-end poison runs,fetch_reposanitization, and manifest regeneration with poison entries. Oracle: the clone-status.jsonl skip-bad-lines contract (github-backup(reconcile): a non-dict JSON line in clone-status.jsonl crashes the failed-clone report path — _clone_status_entries tolerates unparseable lines but not valid non-dict ones #6606).main(the unchanged-behaviour control passes on both); the fullinfra/github-backup/tests/suite is green, including the pre-existingtest_fetch_mirrors.py.Filed from a fallback-mode queue shift (queue backend down, code#6619): claimed and released via
fleet-claimmarkers on #6637 byrepo-worker-code-l.Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.